package com.lzx.iteam;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.widget.*;
import com.lzx.iteam.adapter.AttendanceCalendarListAdapter;
import com.lzx.iteam.bean.ApprovalData;
import com.lzx.iteam.bean.AttendanceCalendarData;
import com.lzx.iteam.bean.AttendanceCalendarMsgData;
import com.lzx.iteam.bean.LegworkRecordData;
import com.lzx.iteam.net.AsynHttpClient;
import com.lzx.iteam.net.GetAttendanceCalendarMsg;
import com.lzx.iteam.net.LocalLogin;
import com.lzx.iteam.provider.AttendanceCalendarDB;
import com.lzx.iteam.provider.CloudDBOperation;
import com.lzx.iteam.widget.schedulecalendar.CalendarAdapter;
import com.lzx.iteam.widget.schedulecalendar.ScrollableLayout;
import com.lzx.iteam.widget.schedulecalendar.SpecialCalendar;
import com.lzx.iteam.widget.schedulecalendar.ViewHelper;
import com.lzx.iteam.util.AllDialogUtil;
import com.lzx.iteam.util.Constants;
import com.lzx.iteam.util.PreferenceUtil;
import com.lzx.iteam.util.StringUtil;
import com.lzx.iteam.widget.CustomGridView;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Megan on 16/4/8.
 */
public class AttendanceCalendarActivity extends Activity implements View.OnClickListener, GestureDetector.OnGestureListener, AdapterView.OnItemClickListener, AdapterView.OnItemLongClickListener {

    private LinearLayout mBtnBack, mNullLayout;
    private LinearLayout mLlAttendanceAppeal;
    private TextView mTvMap;
    private ImageView mIvManager, mIvHelp;
    private ImageView mIvCreate;
    private ImageView mIvPrevious, mIvNext;
    private TextView mTvYear, mTvMonth1, mTvMonth2, mNullText;
    private ScrollableLayout mScrollLayout;
    private CustomGridView mGridView;
    private TextView mTvDay, mTvUserName;
    private ListView mListView;

    private CalendarAdapter calV = null;  // 日历adapter
    private AttendanceCalendarListAdapter mAdapter;
    private GestureDetector gestureDetector = null;
    private AttendanceCalendarActivity mActivity;
    private Dialog mProgressDialog;


    private int jumpMonth = 0;      //每次滑动，增加或减去一个月,默认为0（即显示当前月）
    private int jumpYear = 0;       //滑动跨越一年，则增加或者减去一年,默认为0(即当前年)
    private int mYear;  // 跳转的年份
    private int mMonth; // 跳转的月份
    private int mDay;   // 跳转的日子
    private int year_c = 0;  // 当前的年份
    private int month_c = 0; // 当前的月份
    private int day_c = 0;   // 当前的日子
    private int mPosition = -1; // 删除日程时记录位置
    private float location;             // 最终决定的收缩比例值
    private float currentLoction = 1f;  // 记录当天的收缩比例值
    private float selectLoction = 1f;   // 记录选择那一天的收缩比例值
    private Calendar c;
    private String currentDate = "";
    private String mSelectDate = ""; // 选择的年月日时间戳
    private String scheduleYear;    // 选择的年份
    private String scheduleMonth;   // 选择的月份
    private String scheduleDay;     // 选择的日子
    private String mDate;
    private String mUserId;
    private String mUserName;
    private String mAttendanceFormId;
    private String mGroupId;
    private boolean mIsMy;
    private int mFormType;
    private String mSubName;

    private HashMap<String, Object> mMap = new HashMap<String, Object>();
    private List<Object> datas = new ArrayList<Object>();
    private List<AttendanceCalendarData> mAttendanceCalendarDatas = new ArrayList<AttendanceCalendarData>();
    private AttendanceCalendarDB mAttendanceCalendarDB;
    private CloudDBOperation mCloudDBOperation;

    private final int GET_LIST = 10001;


    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            super.handleMessage(msg);

            switch (msg.what) {
                case GET_LIST:
                    if (msg.arg1 == 0) {
                        mMap = (HashMap<String, Object>) msg.obj;
                        mAttendanceCalendarDatas = (List<AttendanceCalendarData>) mMap.get("calendar");
                        datas = (List<Object>) mMap.get("attendance");
                        /*calV.bindData(mAttendanceCalendarDatas, 1);
                        if (mAttendanceCalendarMsgDatas.size() == 0) {
                            mNullLayout.setVisibility(View.VISIBLE);
                        } else {
                            mNullLayout.setVisibility(View.GONE);
                        }*/
                        setData(0);
                        // mAdapter.bindData(mAttendanceCalendarMsgDatas);
                    } else {
                        if (msg.arg1 == AsynHttpClient.ERROR_LOCAL) {
                            Toast.makeText(mActivity, R.string.active_failure_no_network,
                                    Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(mActivity, (String) msg.obj,
                                    Toast.LENGTH_LONG).show();
                        }
                    }
                    break;
            }

        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.schedule_calendar_layout);
        initView();
        initProperty();
    }

    @Override
    protected void onResume() {
        super.onResume();
        datas = mAttendanceCalendarDB.findAttendanceByDate(mDate, mDay + "", mUserId, mGroupId);
        mAdapter.bindData(datas);
        mAttendanceCalendarDatas = mCloudDBOperation.findAttendanceCalendarData(mUserId, mYear + "", mMonth + "", mGroupId);
        calV.bindData(mAttendanceCalendarDatas, 1);
        getAttendanceCalendarMsg(mYear + "", mMonth + "", mDay + "");
    }

    private void initView() {
        mBtnBack = (LinearLayout) findViewById(R.id.schedule_btn_back);
        mIvHelp = (ImageView) findViewById(R.id.schedule_iv_help);
        mTvMap = (TextView) findViewById(R.id.tv_attendance_map);
        mLlAttendanceAppeal = (LinearLayout) findViewById(R.id.ll_attendance_send_appeal);
        mIvManager = (ImageView) findViewById(R.id.schedule_iv_manager);
        mIvCreate = (ImageView) findViewById(R.id.schedule_iv_create);
        mIvPrevious = (ImageView) findViewById(R.id.calendar_iv_previous);
        mIvNext = (ImageView) findViewById(R.id.calendar_iv_next);
        mTvYear = (TextView) findViewById(R.id.calendar_tv_year);
        mTvMonth1 = (TextView) findViewById(R.id.calendar_tv_month1);
        mTvMonth2 = (TextView) findViewById(R.id.calendar_tv_month2);
        mScrollLayout = (ScrollableLayout) findViewById(R.id.calendar_scrollablelayout);
        mGridView = (CustomGridView) findViewById(R.id.calentar_gridview);
        mTvDay = (TextView) findViewById(R.id.calentar_tv_day);
        mListView = (ListView) findViewById(R.id.calendar_lv_content);
        mNullLayout = (LinearLayout) findViewById(R.id.attendance_ll_rest);
        mNullText = (TextView) findViewById(R.id.tv_attendance_no_data_text);
        mTvUserName = (TextView) findViewById(R.id.schedule_tv_name);

        mIvHelp.setVisibility(View.VISIBLE);
        mTvUserName.setText("考勤");
        mTvMap.setVisibility(View.VISIBLE);
        mIvManager.setVisibility(View.GONE);
        mIvCreate.setVisibility(View.GONE);
        mTvDay.setVisibility(View.GONE);
        findViewById(R.id.calentar_line_day).setVisibility(View.GONE);
        mListView.setOnItemClickListener(this);
        mListView.setOnItemLongClickListener(this);
        mIvPrevious.setOnClickListener(this);
        mIvNext.setOnClickListener(this);
        mBtnBack.setOnClickListener(this);
        mLlAttendanceAppeal.setOnClickListener(this);
        mTvMap.setOnClickListener(this);
        mIvHelp.setOnClickListener(this);
        mNullLayout.setOnClickListener(this);

    }

    public void initProperty() {
        mActivity = this;
        mAttendanceCalendarDB = new AttendanceCalendarDB(mActivity);
        mCloudDBOperation = new CloudDBOperation(this);
        Intent intent = getIntent();
        mFormType = intent.getIntExtra("form_type",0);
        mSubName = intent.getStringExtra("sub_name");
        mUserId = intent.getStringExtra("userId");
        String mUid = PreferenceUtil.getInstance(this).getString(PreferenceUtil.CLIENT_USEID, "－1");
        if (StringUtil.isEmpty(mUserId) || mUserId.equals(mUid)) {
            mUserId = mUid;
            mIsMy = true;
        } else {
            mIsMy = false;
        }
        mUserName = intent.getStringExtra("userName");
        if (!StringUtil.isEmpty(mUserName) && !mIsMy) {
            mTvUserName.append("(" + mUserName + ")");
        }

        mGroupId = intent.getStringExtra("group_id");
        mAttendanceFormId = intent.getStringExtra("form_id");
        c = Calendar.getInstance();
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-M-d");
        currentDate = sdf.format(date);  //当期日期
        year_c = Integer.parseInt(currentDate.split("-")[0]);
        month_c = Integer.parseInt(currentDate.split("-")[1]);
        day_c = Integer.parseInt(currentDate.split("-")[2]);

        if ("0".equals(mGroupId)) {
            mYear = 2016;
            mMonth = 4;
            mDay = 1;
            jumpYear = 2016 - year_c; // 和当年的年份差
            jumpMonth = 4 - month_c;  // 和当月的月份差
        } else {
            mYear = year_c;
            mMonth = month_c;
            mDay = day_c;
        }

        Constants.zYear = mYear + "";
        Constants.zMonth = mMonth + "";
        Constants.zDay = mDay + "";

        // TODO 查看成员的考勤记录
        int year = intent.getIntExtra("year",0);
        int month = intent.getIntExtra("month",0);
        if (year != 0 && month != 0){
            mYear = year;
            mMonth = month;
            // 可以查看当月和之前的3个月份
            if (mYear == year_c){
                mDay = day_c;
                jumpMonth = month - month_c;
            }else{
                mDay = 1;
                jumpMonth = Math.abs(month_c - month) - 12;
            }
        }

        mDate = mYear + "_" + mMonth;

        // TODO 计算当天的位置和收缩比例
        SpecialCalendar calendar = new SpecialCalendar();
        boolean isLeapYear = calendar.isLeapYear(mYear);
        int days = calendar.getDaysOfMonth(isLeapYear, mMonth);
        int dayOfWeek = calendar.getWeekdayOfMonth(mYear, mMonth);
        int todayPosition = mDay;
        if (dayOfWeek != 7) {
            days = days + dayOfWeek;
            todayPosition += dayOfWeek - 1;
        } else {
            todayPosition -= 1;
        }
        /**
         * 如果 少于或者等于35天显示五行 多余35天显示六行
         * 五行: 收缩比例是：0.25，0.5，0.75，1
         * 六行: 收缩比例是：0.2，0.4，0.6，0.8，1
         */
        if (days <= 35) {
            Constants.scale = 0.25f;
            currentLoction = (4 - todayPosition / 7) * Constants.scale;
        } else {
            Constants.scale = 0.2f;
            currentLoction = (5 - todayPosition / 7) * Constants.scale;
        }
        location = currentLoction;
        mScrollLayout.setVisibleHeight(46f);
        mScrollLayout.setOnScrollListener(new ScrollableLayout.OnScrollListener() {
            @Override
            public void onScroll(int currentY, int maxY) {

                ViewHelper.setTranslationY(mGridView, currentY * location);
            }
        });
        mScrollLayout.getHelper().setCurrentContainer(mListView);

        gestureDetector = new GestureDetector(this);
        calV = new CalendarAdapter(this, getResources(), jumpMonth, jumpYear, year_c, month_c, day_c, mGroupId);
        mGridView.setAdapter(calV);
        addGridView();
        addTextToTopTextView();

        mAdapter = new AttendanceCalendarListAdapter(this, mIsMy, mUserId);
        if (mFormType == 1){
            mAdapter.setSubName(mFormType,mSubName);
        }
        mListView.setAdapter(mAdapter);


    }

    private void httpReqDlgShow() {
        if (mProgressDialog == null) {
            mProgressDialog = AllDialogUtil.getInstance(this).waitDialog();
//            mProgressDialog.setCancelable(false);
            mProgressDialog.show();
        }

    }

    private void httpReqDlgDismiss() {
        if (mProgressDialog != null && mProgressDialog.isShowing()) {
            mProgressDialog.dismiss();
            mProgressDialog = null;
        }
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.schedule_btn_back:
                finish();
                break;
            case R.id.calendar_iv_previous:
                if (!"0".equals(mGroupId)) {
                    changeView(false);
                }
                break;
            case R.id.calendar_iv_next:
                if (!"0".equals(mGroupId)) {
                    changeView(true);
                }
                break;
            case R.id.tv_attendance_map:
                /*Intent rules = new Intent(mActivity, AttendanceRulesActivity.class);
                startActivity(rules);*/
                Intent map=new Intent(mActivity,LegworkMapRecordActivity.class);
                ArrayList<LegworkRecordData> recordDatas=new ArrayList<LegworkRecordData>();
                for(int i=0;i<datas.size();i++){
                    if(datas.get(i) instanceof LegworkRecordData){
                        recordDatas.add((LegworkRecordData)datas.get(i));
                    }
                }
                map.putExtra("recordData",recordDatas);
                startActivity(map);
                break;
            case R.id.schedule_iv_help:
                Intent rules = new Intent(mActivity, AttendanceRulesActivity.class);
                startActivity(rules);
                break;
            case R.id.ll_attendance_send_appeal:
                /*Intent intent = new Intent(mActivity, ApprovalCreateActivity.class);
                ApprovalData approvalData = new ApprovalData();
                for (AttendanceCalendarMsgData attendanceCalendarMsgData : mAttendanceCalendarMsgDatas) {
                    if ("1".equals(attendanceCalendarMsgData.getStatus()) || "2".equals(attendanceCalendarMsgData.getStatus())) {
                        approvalData.setApproval_start_time(attendanceCalendarMsgData.getTime());
                        approvalData.setApproval_start_part(Integer.parseInt(attendanceCalendarMsgData.getPart()));
                        break;
                    }
                }
                approvalData.setApproval_type(4);
                approvalData.setApproval_group_id(mGroupId);
                intent.putExtra("approvalData", approvalData);
                startActivity(intent);*/
                break;
            case R.id.attendance_ll_rest:
                break;
        }
    }

    public void sendApproval(AttendanceCalendarMsgData attendanceCalendarMsgData) {

        Intent intent = new Intent(this, ApprovalCreateActivity.class);
        ApprovalData approvalData = new ApprovalData();
        approvalData.setApproval_start_time(mSelectDate);
        approvalData.setApproval_start_part(Integer.parseInt(attendanceCalendarMsgData.getPart()));
        approvalData.setApproval_type(4);
        approvalData.setApproval_group_id(mGroupId);
        intent.putExtra("approvalData", approvalData);
        intent.putExtra("atten_calendar_id",attendanceCalendarMsgData.getAtten_calendar_id());
        intent.putExtra("atten_record_id",attendanceCalendarMsgData.get_id());
        intent.setAction("attendance_to_approval");
        startActivity(intent);

    }

    private void changeView(boolean flag) {
        if (flag) {
            //像左滑动
            jumpMonth++;     //下一个月
            mMonth++;
            if (mMonth > 12) {
                mMonth = 1;
                mYear++;
            }
        } else {
            //向右滑动
            jumpMonth--;     //上一个月
            mMonth--;
            if (mMonth < 1) {
                mMonth = 12;
                mYear--;
            }
        }
        updateView();
    }

    //添加gridview
    private void addGridView() {

        if (jumpMonth == 0) {
            location = currentLoction;
        } else {
            location = 1f;
        }
        if (((jumpMonth + month_c) + "").equals(Constants.zMonth) && jumpMonth != 0) {
            location = selectLoction;
        }

        Log.d("location", "location == " + location + "   currentLoction == " + currentLoction);
        if (!"0".equals(mGroupId)) {
            mGridView.setOnTouchListener(new View.OnTouchListener() {
                //将gridview中的触摸事件回传给gestureDetector
                @Override
                public boolean onTouch(View v, MotionEvent event) {
                    // TODO Auto-generated method stub
                    return mActivity.gestureDetector.onTouchEvent(event);
                }
            });
        }

        mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            //gridView中的每一个item的点击事件
            @Override
            public void onItemClick(AdapterView<?> arg0, View arg1, int position,
                                    long arg3) {
                //点击任何一个item，得到这个item的日期(排除点击的是周日到周六(点击不响应))
                int startPosition = calV.getStartPositon();
                int endPosition = calV.getEndPosition();

                if (Constants.scale == 0.2f) {
                    location = (5 - position / 7) * Constants.scale;
                } else {
                    location = (4 - position / 7) * Constants.scale;
                }
                selectLoction = location;
                if (startPosition <= position + 7 && position <= endPosition - 7) {
                    scheduleDay = calV.getDateByClickItem(position).split("\\.")[0];  //这一天的阳历
//                    String scheduleLunarDay = calV.getDateByClickItem(position).split("\\.")[1];  //这一天的阴历
                    scheduleYear = calV.getShowYear();
                    scheduleMonth = calV.getShowMonth();
                    Constants.zYear = scheduleYear;
                    Constants.zMonth = scheduleMonth;
                    Constants.zDay = scheduleDay;
                    calV.notifyDataSetChanged();
                    mYear = Integer.parseInt(scheduleYear);
                    mMonth = Integer.parseInt(scheduleMonth);
                    mDay = Integer.parseInt(scheduleDay);
                    /*c.set(mYear, mMonth - 1, mDay, 00, 00, 00);
                    mSelectDate = c.getTimeInMillis()/1000 + "";*/
                    setData(0);

                }
            }

        });
    }

    /**
     * 更新年月
     *
     * @param
     */
    public void addTextToTopTextView() {
        int month;
        if ("0".equals(mGroupId)) {
            mTvYear.setText(mYear + "年");
            month = mMonth;
        } else {
            mTvYear.setText(calV.getShowYear() + "年");
            month = Integer.parseInt(calV.getShowMonth());
        }
        int month1 = month / 10;
        int month2 = month % 10;
        mTvMonth1.setText(month1 + "");
        mTvMonth2.setText(month2 + "");

    }

    /**
     * 显示选择的 日期
     *
     * @param year
     * @param month
     * @param day
     */
    private void setSelectDay(int year, int month, int day) {
        /*String time = month + "月" + day + "日";
        if (year == year_c && month == month_c) {
            int d = day - day_c;
            switch (d) {
                case -2:
                    time = "前天";
                    break;
                case -1:
                    time = "昨天";
                    break;
                case 0:
                    time = "今天";
                    break;
                case 1:
                    time = "明天";
                    break;
                case 2:
                    time = "后天";
                    break;
                default:
                    mTvDay.setText(month + "月" + day + "日");
                    break;
            }
//            mTvDay.setText(time);
        } else {
            if (year == year_c) {
                mTvDay.setText(month + "月" + day + "日");
            } else {
                mTvDay.setText(year + "年" + month + "月" + day + "日");
            }
        }*/
        c.set(mYear, mMonth - 1, mDay, 00, 00, 00);
        mSelectDate = c.getTimeInMillis() / 1000 + "";
    }

    @Override
    public boolean onDown(MotionEvent e) {
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        return false;
    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {

    }

    /**
     * 滑动的手势监听
     *
     * @param e1
     * @param e2
     * @param velocityX
     * @param velocityY
     * @return
     */
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        if (e1.getX() - e2.getX() > 120) {
            //像左滑动
            jumpMonth++;     //下一个月
            mMonth++;
            if (mMonth > 12) {
                mMonth = 1;
                mYear++;
            }
            updateView();
            return true;
        } else if (e1.getX() - e2.getX() < -120) {
            //向右滑动
            jumpMonth--;     //上一个月
            mMonth--;
            if (mMonth < 1) {
                mMonth = 12;
                mYear--;
            }
            updateView();
            return true;
        }
        return false;
    }

    /**
     * 月份切换，刷新日历表
     */
    private void updateView() {
        addGridView();   //添加一个gridView
        calV = new CalendarAdapter(this, getResources(), jumpMonth, jumpYear, year_c, month_c, day_c, mGroupId);
        mGridView.setAdapter(calV);
        addTextToTopTextView();
        Log.d("Year and Month", "changeView  Month == " + mMonth + "   Year  == " + mYear);
        if (jumpMonth == 0) {
            Constants.zYear = year_c + "";
            Constants.zMonth = month_c + "";
            Constants.zDay = day_c + "";
            mDay = day_c;
        } else {
            if (Constants.zYear.equals(mYear + "") && Constants.zMonth.equals(mMonth + "")) {
                mDay = Integer.parseInt(Constants.zDay);
            } else {
                mDay = 1;
            }
        }
        setData(1);

    }

    /**
     * @param type 1:月份切换
     */
    private void setData(int type) {
        mDate = mYear + "_" + mMonth;
        datas = mAttendanceCalendarDB.findAttendanceByDate(mDate, mDay + "", mUserId, mGroupId);
        if (datas.size() > 0) {
            mNullLayout.setVisibility(View.GONE);
        } else {
            if (year_c == mYear && month_c == mMonth && day_c == mDay) {
                mNullLayout.setVisibility(View.VISIBLE);
                mNullText.setText("暂无考勤信息");
            } else {
                mNullLayout.setVisibility(View.VISIBLE);
                if (jumpMonth > 0 || (!StringUtil.isEmpty(Constants.zDay) && Integer.parseInt(Constants.zDay) > day_c)) {
                    mNullText.setText("暂无考勤信息");
                } else {
                    mNullText.setText("放假了！");
                }
            }

        }
        mAdapter.bindData(datas);
        mAttendanceCalendarDatas = mCloudDBOperation.findAttendanceCalendarData(mUserId, mYear + "", mMonth + "", mGroupId);
        calV.bindData(mAttendanceCalendarDatas, 1);
     /*   boolean flag = false;//发起申诉按钮是否显示
        for (AttendanceCalendarMsgData attendanceCalendarMsgData : mAttendanceCalendarMsgDatas) {
            if ("0".equals(attendanceCalendarMsgData.getStatus()) || "1".equals(attendanceCalendarMsgData.getStatus()) || "2".equals(attendanceCalendarMsgData.getStatus())) {
                flag = true;
            }
        }

        if (mIsMy && flag) {
            mLlAttendanceAppeal.setVisibility(View.VISIBLE);
        } else {
            mLlAttendanceAppeal.setVisibility(View.GONE);
        }
*/
        if (type == 1) {
            getAttendanceCalendarMsg(mYear + "", mMonth + "", mDay + "");
        }
        setSelectDay(mYear, mMonth, mDay);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        if (datas.get(position) instanceof AttendanceCalendarMsgData) {
            if ("2".equals(((AttendanceCalendarMsgData) datas.get(position)).getType())) {
                Intent intent = new Intent(AttendanceCalendarActivity.this, ApprovalDetailActivity.class);
                intent.setAction("attendance");
                intent.putExtra("approval_id", ((AttendanceCalendarMsgData) datas.get(position)).get_id());
                startActivity(intent);
            }
        } else if (datas.get(position) instanceof LegworkRecordData) {
            Intent intent = new Intent(AttendanceCalendarActivity.this, LegworkDetailActivity.class);
//            intent.putExtra("record_data", (LegworkRecordData) datas.get(position));

            ArrayList<LegworkRecordData> mRecordDatas = new ArrayList<>();
            for (int i = 0; i < datas.size(); i++) {
                if (datas.get(i) instanceof LegworkRecordData){
                    mRecordDatas.add((LegworkRecordData)datas.get(i));
                }
            }
            intent.putExtra("record_datas", mRecordDatas);
            intent.putExtra("page_index",mRecordDatas.size() - (datas.size() - position));
            startActivity(intent);
        }


    }

    @Override
    public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

       /* if (mCalendarData.get(position) instanceof ScheduleData){
            ScheduleData data = (ScheduleData) mCalendarData.get(position);
            mCalendarId = data.getId();
            mType = "1";
        }else{
            EventListData eventListData= (EventListData) mCalendarData.get(position);
            mCalendarId = eventListData.getEventId();
            mType = "9";
        }
        if ("1".equals(mType) && !mIsMy && "1".equals(((ScheduleData)mCalendarData.get(position)).getHidden())){
            Toast.makeText(mActivity,"您没有权限删除此日程",Toast.LENGTH_SHORT).show();
        }else{
            mPosition = position;
            String okText = this.getString(R.string.label_btn_delete);
            String cancelText = this.getString(R.string.cancel);
            mDialogUtil.titleDeleteMsgStyle(okText, cancelText, "删除此日程");
            mDialogUtil.setOnDialogListener(new AllDialogUtil.DialogOnClickListener() {
                @Override
                public void onConfirmClick(Dialog lDialog) {
                    httpReqDlgShow();
                    deleteCalendar(mCalendarId);
                    lDialog.dismiss();
                }

                @Override
                public void onCancelClick(Dialog lDialog) {
                    lDialog.dismiss();
                }
            });
        }
*/
        return true;
    }


    private void getAttendanceCalendarMsg(String year, String month, String day) {
        mDate = year + "_" + month;
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_SID, LocalLogin.getInstance().mSid));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_MONTH, year + "_" + month));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_ATTENDANCE_FORM_ID, mAttendanceFormId));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_GROUP_ID, mGroupId));
        nvps.add(new BasicNameValuePair(AsynHttpClient.KEY_ATTENDANCE_UID, mUserId));
        GetAttendanceCalendarMsg msg = new GetAttendanceCalendarMsg(mHandler.obtainMessage(GET_LIST), this, year, month, day, mUserId, mGroupId);
        msg.mParams = nvps;
        msg.mApi = AsynHttpClient.API_EVENT_ATTENDANCE_USER_STATISTICS;
        AsynHttpClient.getInstance(this).execEventHttp(msg);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        // TODO 页面被销毁时，清空选择的日期数据
        Constants.zYear = "";
        Constants.zMonth = "";
        Constants.zDay = "";
    }


}
